<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>

import * as echarts from 'echarts'
import resize from '@/mixins/resize'

export default {
  mixins: [resize],
  name: 'EChart',
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },
  data () {
    return {
      chart: null,
    }
  },
  mounted () {
  },
  beforeDestroy () {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    /**
     * 图表创建初始化
     */
    initChart (option) {
      this.$echarts.getInstanceByDom(this.$el) || (this.chart = echarts.init(this.$el, 'macarons'))

      this.chart.setOption(option, true)
    },
  }
}
</script>